package com.ketai.web;

import com.ketai.query.ResearchQuery;
import com.ketai.service.ResearchService;
import com.ketai.service.impl.ResearchServiceImpl;
import com.ketai.util.Pages;
import com.ketai.util.SendUtil;
import com.ketai.vo.ResearchVo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 研学servlet
 *
 * @author
 * @date 2022-08-10 13:18
 */

@WebServlet(urlPatterns = "/research")
public class ResearchServlet extends HttpServlet {
    ResearchService researchService = new ResearchServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //先获取参数
        String opr = req.getParameter("opr");
        //分页查询
        if ("list".equals(opr)) {
            String curr = req.getParameter("page");
            String limit = req.getParameter("limit");
            String type = req.getParameter("type");
            ResearchQuery researchQuery = new ResearchQuery(curr, limit,type);
            Pages<ResearchVo> pages = researchService.getAllResearchs(researchQuery);
            SendUtil.SendPageJson(resp, pages);
        }
    }
}
